package com.musketeers.tiktok.service.impl;

import java.util.List;

import com.musketeers.common.core.domain.entity.SysUser;
import com.musketeers.common.utils.SecurityUtils;
import com.musketeers.system.mapper.SysUserMapper;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.musketeers.tiktok.mapper.TiktokNumberMapper;
import com.musketeers.tiktok.domain.TiktokNumber;
import com.musketeers.tiktok.service.ITiktokNumberService;

/**
 * 我的抖音Service业务层处理
 *
 * @author musketeers
 * @date 2023-12-27
 */
@Service
public class TiktokNumberServiceImpl implements ITiktokNumberService
{
    @Autowired
    private TiktokNumberMapper tiktokNumberMapper;

    @Autowired
    private SysUserMapper userMapper;


    /**
     * 查询我的抖音
     *
     * @param id 我的抖音主键
     * @return 我的抖音
     */
    @Override
    public TiktokNumber selectTiktokNumberById(Long id)
    {
        return tiktokNumberMapper.selectTiktokNumberById(id);
    }

    /**
     * 查询我的抖音列表
     *
     * @param tiktokNumber 我的抖音
     * @return 我的抖音
     */
    @Override
    public List<TiktokNumber> selectTiktokNumberList(TiktokNumber tiktokNumber)
    {
        SecurityUtils securityUtils = new SecurityUtils();
        if (!securityUtils.getUsername().equals("admin")){
            tiktokNumber.setUserNumber(securityUtils.getUsername());
        }
        return tiktokNumberMapper.selectTiktokNumberList(tiktokNumber);
    }

    /**
     * 新增我的抖音
     *
     * @param tiktokNumber 我的抖音
     * @return 结果
     */
    @Override
    public int insertTiktokNumber(TiktokNumber tiktokNumber)
    {
        TiktokNumber tiktokNumber1 = new TiktokNumber();
        SecurityUtils securityUtils = new SecurityUtils();
        tiktokNumber.setUserNumber(securityUtils.getUsername());
        tiktokNumber1.setUserNumber(securityUtils.getUsername());
        int i = tiktokNumberMapper.selectTiktokNumberList(tiktokNumber1).size();
        if (i <= 9) {
            return tiktokNumberMapper.insertTiktokNumber(tiktokNumber);
        }else {
            return 0;
        }
    }

    /**
     * 修改我的抖音
     *
     * @param tiktokNumber 我的抖音
     * @return 结果
     */
    @Override
    public int updateTiktokNumber(TiktokNumber tiktokNumber)
    {
        SecurityUtils securityUtils = new SecurityUtils();
        tiktokNumber.setUserNumber(securityUtils.getUsername());
        return tiktokNumberMapper.updateTiktokNumber(tiktokNumber);
    }

    /**
     * 批量删除我的抖音
     *
     * @param ids 需要删除的我的抖音主键
     * @return 结果
     */
    @Override
    public int deleteTiktokNumberByIds(Long[] ids)
    {
        return tiktokNumberMapper.deleteTiktokNumberByIds(ids);
    }

    /**
     * 删除我的抖音信息
     *
     * @param id 我的抖音主键
     * @return 结果
     */
    @Override
    public int deleteTiktokNumberById(Long id)
    {
        return tiktokNumberMapper.deleteTiktokNumberById(id);
    }
}
